package com.nightpiter.view.drawer.rapid;

import static com.nightpiter.view.drawer.rapid.Config.tunnelWidth;

import java.util.List;

import com.nightpiter.view.graphics.Canvas;
import com.nightpiter.view.graphics.PointF;

public class SimpleLinkDrawer extends LinkDrawer {

	@Override
	public void draw(Canvas canvas, Link link) {
		draw(canvas, link.evenPointF, link.oddPointF, link.colors);
	}

	public void draw(Canvas canvas, PointF from, PointF to, List<Integer> colors) {
		PointF normal = PointF.difference(from, to);
		normal.rotateCW();
		normal.normalize();
		normal.scale(tunnelWidth);
		if (colors.size() == 1) {
			getTunnelPaint().setColor(colors.get(0));
			canvas.drawLine(from, to, getTunnelPaint());
		} else if (colors.size() == 0) {
			canvas.drawLine(from, to, getTransferPaint());
		} else {
			PointF offset = new PointF(normal);
			offset.scale((float) (1 - colors.size()) / 2);
			for (int color : colors) {
				getTunnelPaint().setColor(color);
				canvas.drawLine(PointF.sum(from, offset), PointF
						.sum(to, offset), getTunnelPaint());
				offset.add(normal);
			}
		}
	}

}
